class Import < ActiveRecord::Base

  # 添加默认用户
  # 2012.08.22
  # ruby script/runner Import.users
  def self.users
    user = User.find_or_initialize_by_login('winseed')
    user.name = "winseed"
    user.login = "winseed"
    user.email = "gauseed@qq.com"
    user.password = "123456"
    user.password_confirmation = "123456"
    user.save!
    # 创建默认画板
    board = Board.create({:name => "默认画板", :user_id => user.id})
  end

  CATEGORIES = ["家居", "旅行", "美食", "摄影", "宠物", "手工/布艺/玩具", "男人志", "运行/酷玩",
                "人物", "音乐/电影/图书", "美女", "趣味", "欲望清单", "生活百科", "汽车", 
                "人文艺术", "建筑", "童真", "创意/设计", "网站/App/Icon", "3C数码",
                "数据/显示", "造型/状发", "服饰/搭配/街拍", "婚纱/婚礼", "其他"
                ]

  # 添加默认用户
  # 2012.08.27
  # ruby script/runner Import.categories
  def self.categories
    CATEGORIES.each do |category|
      Category.create({:name => category}) 
    end
  end
  
  # 执行所有batch
  # 2012.08.22
  # ruby script/runner Import.run_all_batch
  def self.run_all_batch
    # 取得import类中所有的类方法
    methods = Import.singleton_methods(false)
    methods.each do |method|
      next if method == "run_all_batch"# || method == "add_default"
      pp "Running: #{method}"
      begin
        Import.try(method.to_sym)
      rescue => e
        pp e.message
      end
      pp "End: #{method}"
    end
  end
  
end